import { createDraw } from "../../../utils/createDraw"
import { docLayer } from "../../Map/Hooks/useGuangguMap"
import { Point } from "../../../utils/Point"

// 控制弹窗显示
export let dialogFormVisible = ref(false)
export const addevent_source = new ol.source.Vector({})
const addevent_layer = new ol.layer.Vector({
  source: addevent_source,
  title: "事件添加图层",
})
export let draw
let position
export function getDrawPosition(map) {
  map.addLayer(addevent_layer)
  draw = createDraw({
    source: addevent_source,
    type: "Point",
  })
  map.addInteraction(draw)
  draw.on("drawend", (e) => {
    draw.setActive(false)
    dialogFormVisible.value = true
    position = e.feature.getGeometry().getCoordinates()
  })
}
export function removeDrawPosition() {
  draw.setActive(false) //画笔失活
}

export function getEventAdd(form) {
  // const position = e.feature.getGeometry().getCoordinates()
  let service = {
    name: "guanggu",
    layerId: 2,
  }
  var attr = [
    { key: "事件编号", value: form.event_number, type: "string" },
    {
      key: "事件类型",
      value: form.event_type,
      type: "string",
    },
    {
      key: "事件等级",
      value: Number(form.event_level),
      type: "number",
    },
    {
      key: "发生时间",
      value: form.event_time,
      type: "string",
    },
    {
      key: "发生地点",
      value: form.event_addr,
      type: "string",
    },
    {
      key: "车牌号",
      value: form.event_car,
      type: "string",
    },
    {
      key: "驾驶员",
      value: form.event_person,
      type: "string",
    },
    {
      key: "处理状态",
      value: Number(form.event_state),
      type: "number",
    },
  ]
  var pointColor
  if (form.event_state == 0) {
    pointColor = 6
  } else if (form.event_state == 1) {
    pointColor = 4
  } else if (form.event_state == 2) {
    pointColor = 90
  }

  const POINT_STYLE = {
    Angle: 0,
    Color: pointColor,
    Space: 0,
    SymHeight: 5,
    SymID: 21,
    SymWidth: 5,
  }
  Point.add({ position, service, docLayer, attr, POINT_STYLE })
  // 清空容器
  addevent_source.clear()
}
